<?php 
ob_start();
session_start();
include('./src/inst.conf.php');
include('./src/functions.php');

if(isset($_GET['logoff'])){session_destroy();header("location: ".$_SERVER['PHP_SELF']."");}
if (!isset($_SESSION['LOGIN_USERNAME'] ) || !isset( $_SESSION['LOGIN_PASSWORD'] )){   
	if(isset($_GET['login'])){
		$GEBRUIKERSNAAM= secure($_POST['gebruikersnaam']);
		$WACHTWOORD= hash("sha256", secure($_POST['wachtwoord']));
		$result = mysql_query("SELECT * FROM `DOCENT` WHERE `GEBRUIKERSNAAM` = '$GEBRUIKERSNAAM' AND `WACHTWOORD` = '$WACHTWOORD'"); 
		$row = mysql_fetch_array($result);
		if (!$row['GEBRUIKERSNAAM'] ==""){
			$_SESSION['LOGIN_ID'] = $row['DOCENT_ID'];
			$_SESSION['LOGIN_USERNAME'] = $row['GEBRUIKERSNAAM'];
			$_SESSION['LOGIN_PASSWORD'] = $row['WACHTWOORD'];
			header("location: ./"); 
		}else{
			$failMessage= "U heeft een onjuiste gebruikersnaam en of wachtwoord opgegeven";
		}
		
	}

}
ob_end_flush();
if (strpos(strtolower($_SERVER['HTTP_USER_AGENT']), "chrome")){
	?>
	<html>
	<head>
	<style>
	#CHROME-display {
	  position: fixed;
	  top: 50%;
	  /*bottom: 50%;*/
	  left: 50%;
	  /*right: 50%;*/
	  background-image: url('./css/images/message.png');
	  background-repeat: no-repeat; 
	  background-position:0px 0px;
	  color: #000;
	  z-index: 9999;
	  text-align: center;
	  width: 550px;
	  height: 305px;
	  margin-top: -152px; /* Half the height */
	  margin-left: -275px; /* Half the width */
	  padding-top: 15px;
	  line-height: 6pt;
	  -webkit-border-radius: 6px;
	  -moz-border-radius: 6px;
	  border-radius: 6px;
	}
	
	#CHROME-content{
		position:relative;
		top: 40px;
		left: 40px;
		font-size: 14px;
		width: 460px;
		text-align: left;
		line-height: 105%;
	}
	#CHROME-title {
		position: relative;
		text-align: left;
		font-size: 18px;
		top: 35px;
		left: 130px;
		
		
	}
	#CHROME-icon {
		width:65px;
		height:53px;
		position:absolute;
		top:40px;
		left:40px;
		background-image: url('./css/images/sad_chrome.png');
		background-repeat: no-repeat; 
	}
	#CHROME-background {
	  position: fixed;
	  top: 0;
	  bottom: 0%;
	  left: 0;
	  right: 0%;
	  background-color: black;
	  z-index: 9998;
	  text-align: center;
	  width: 100%;
	  padding-top: 25px;
	  opacity:0.9;
	  filter:alpha(opacity=90);
	}
	</style>
	</head>
	<body>
	<!---CHROME Message-->
	<div id="CHROME-background"></div>
	<div id="CHROME-display"><a href="javascript:void('0');" id="CHROME-icon"></a><h3 id="CHROME-title">Chrome word [nog] niet ondersteund</h3><div id="CHROME-content">Heelaas.. deze site werkt nog niet in het Google Chrome browser.. We zijn er van op de hoogte en doen er alles aan om hem ook in Chrome werkend te krijgen.<br><br><br>Excuses voor het ongemak.<br><br><br><br><span style="color:#F00;">Op dit moment ondersteund: Internet Explorer, Firefox & Safari </span></div></div>
	<!--END CHROME Message-->
	</body>
	</html>
	<?
	exit;
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="nl">
<head profile="http://gmpg.org/xfn/11">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Basisschool Leusden | CBS Groenhorst | Rapporten</title>
	<!--[if IE 7]>	
	<link rel="stylesheet" type="text/css" media="all" href="./css/iestyle.css" />
	<![endif]-->
	<!--[if lt IE 7]>
	<link rel="stylesheet" type="text/css" media="all" href="./css/ie6style.css" />
	<![endif]-->
	
	<link rel="stylesheet" href="./css/style-Green.css" type="text/css" media="screen" />
	<link rel="stylesheet" href="./css/table.css" />
	<link rel="stylesheet" href="./css/button.css" />
	<link rel="stylesheet" type="text/css" href="./css/notify.css" />
	
	<script src="./src/jquery-1.7.1.min.js"  type="text/javascript"></script>
	<script src="./src/jquery.notify.js"     type="text/javascript"></script>
	<script src="./src/LAL.plugin.js.php"    type="text/javascript"></script>
	<script src="./src/jquery.idle-timer.js" type="text/javascript"></script>
	<script src="./src/vibarate.js"          type="text/javascript"></script>
	
</head>
<body>
	<div id="header">
		<div style="width: 950px; margin: auto;">
			<a href="http://www.cbsgroenhorst.nl">
				<img src="./css/images/logo.gif" alt="logo" class="logo" />
			</a>
			
					</div>
		<div style="clear: both;"></div>
		<!--Begin Pages Navigation Bar-->
		<div id="pages">
			<ul class="nav superfish links" id="">
				<li class="page_item current_page_item info" id="userinfo">U bent niet aangemeld...</li>
			</ul>
			<ul class="nav superfish rechts" id="usermenu">
				<li></li>
			</ul>
		</div>
		<!--End Pages Navigation Bar-->
		<!--Begin Categories Navigation Bar-->
		<div id="categories">
			<ul class="nav superfish" id="submenu">
				<li></li>
			</ul>
		</div>
		<!--End category navigation-->
	</div>
	
	<div id="wrapper2">
<script language="javascript" type="text/javascript">

        needToConfirm = false;

        window.onbeforeunload = askConfirm;

        function askConfirm(){

                if (needToConfirm){

                        return "De ingevoerde gegevens zijn nog niet opgeslagen.\n weet u zeker dat u deze pagina wilt verlaten?";

                        }       

                }

</script>

<script language="javascript" type="text/javascript">
var t;
var IDLE_Active = false;
function SessionTimer(){
	t=setTimeout("KeepSessionAlive()",5000);
}

function KeepSessionAlive() {
	$.getJSON("./src/login.json.php", { KeepSessionAlive: "true" }, function(j) {
		if(j[0].status == "change"){
			$('#userinfo').fadeOut('100',function(){$('#userinfo').html(j[0].userinfo).fadeIn('slow');$('#userinfo').fadeIn('200');});
			if(j[0].usermenu != ""){$('#usermenu').fadeOut('100',function(){$('#usermenu').html(j[0].usermenu).fadeIn('slow');$('#usermenu').fadeIn('200');});}
			if(j[0].submenu != ""){$('#submenu').fadeOut('100',function(){$('#submenu').html(j[0].submenu);$('#submenu').fadeIn('200');});}
			if( j[0].containerLoad != ""){
				$('#container').fadeOut('100',function(){$('#container').load(j[0].containerLoad,function(){$('#container').fadeIn('200')});});
			}else{
				if(j[0].container != ""){$('#container').fadeOut('100',function(){$('#container').html(j[0].container);$('#container').fadeIn('200');});}
			}
		}else if(j[0].status == "update"){
			if(j[0].UpdateInProgress == "true"){
				UPDATE_Message_show();
			}else{
				$.notify({text: j[0].updateText, title: 'Update', icon:'images/dialog-warning.png'});
			}
		}else if(j[0].status == "Noting has changed" && j[0].UpdateInProgress == "false"){
			UPDATE_Message_hide();
		}
	});
	SessionTimer();
}

function doJASON(whattodo){
	if(whattodo == "aanmelden"){
		 $.post('./src/login.json.php', { u: $('#gebruikersnaam').val(), p: $('#wachtwoord').val() },
		             function(j){
		                 if(j[0].status == "succes"){
		                 	$('#userinfo').fadeOut('100',function(){$('#userinfo').html(j[0].userinfo).fadeIn('slow');$('#userinfo').fadeIn('200');});
		                 	$('#usermenu').fadeOut('100',function(){$('#usermenu').html(j[0].usermenu).fadeIn('slow');$('#usermenu').fadeIn('200');});
		                 	$('#submenu').fadeOut('100',function(){$('#submenu').html(j[0].submenu);$('#submenu').fadeIn('200');});	
		                 	if( j[0].containerLoad != ""){
		                 		$('#container').fadeOut('100',function(){$('#container').load(j[0].containerLoad,function(){$('#container').fadeIn('200')});});
		                 	}else{
		                 		$('#container').fadeOut('100',function(){$('#container').html(j[0].container);$('#container').fadeIn('200');});
		                 	}
		                 	$.idleTimer(<?=$cfg['general']['idle']['sec'];?>);
		                 	SessionTimer();
		                 }else{
		                 	$.notify({text: j[0].errorText, title: j[0].errorTitle, icon:'images/dialog-error.png'});
		                 }
		             }, 'json');
    }else if(whattodo == "afmelden"){
    	$.getJSON("./src/login.json.php", { logoff: "true" }, function(j) {
    		if(j[0].status == "succes"){
    			$('#userinfo').fadeOut('100',function(){$('#userinfo').html(j[0].userinfo).fadeIn('slow');$('#userinfo').fadeIn('200');});
    			$('#usermenu').fadeOut('100',function(){$('#usermenu').html(j[0].usermenu).fadeIn('slow');$('#usermenu').fadeIn('200');});
    			$('#submenu').fadeOut('100',function(){$('#submenu').html(j[0].submenu);$('#submenu').fadeIn('200');});	
    			$('#container').fadeOut('100',function(){$('#container').html(j[0].container);$('#container').fadeIn('200');});
    			$.idleTimer('destroy');
    			clearTimeout(t);
    			
    		}else{
    			$.notify({text: j[0].errorText, title: j[0].errorTitle, icon:'images/dialog-error.png'});
    		}
    	});
    }
}
$(document).ready(function() {
	$('#gebruikersnaam').focus();
	$.getJSON("./src/login.json.php", { IsLogedIn: "check", page: '<?=@$_GET['page'];?>' }, function(j) {
	    if(j[0].status == "succes"){
	    	showLoader('Inloggen', 'u wordt aangemeld. een moment geduld');
	    	$('#userinfo').fadeOut('100',function(){$('#userinfo').html(j[0].userinfo).fadeIn('slow');$('#userinfo').fadeIn('200');});
	    	$('#usermenu').fadeOut('100',function(){$('#usermenu').html(j[0].usermenu).fadeIn('slow');$('#usermenu').fadeIn('200');});
	    	$('#submenu').fadeOut('100',function(){$('#submenu').html(j[0].submenu);$('#submenu').fadeIn('200');});	
	    	if( j[0].containerLoad != ""){
	    		$('#container').fadeOut('100',function(){addLoadDetails('Gegevens downloaden van \''+j[0].containerLoad+'\'');$('#container').load(j[0].containerLoad,function(){$('#container').fadeIn('200');hideLoader();});});
	    	}else{
		    	$('#container').fadeOut('100',function(){$('#container').html(j[0].container);$('#container').fadeIn('200');hideLoader();});
		    }
		    if (j[0].user_idle == "true"){
		    	IDLE_Active = true;
		    	$.getJSON("./src/login.json.php", { UserIsInActive: "true" }, function(j) {
		    	    if(j[0].status == "succes"){	    			
		    	    	showIDLE_Message('U was langer dan <?=$cfg['general']['idle']['min'];?> min inactief',j[0].UserName);
		    	    	//$.idleTimer('destroy');
		    	    }
		    	 });
		    }
		    if (j[0].UpdateInProgress == "true"){
		    	UPDATE_Message_show();
		    }
		    SessionTimer();
		    $.idleTimer(<?=$cfg['general']['idle']['sec'];?>);	    			
	    }
	 });
	 
});	

function LoadContend(targetID, FileToLoad){
	$('#' + targetID).fadeOut(100, function() {
		$('#' + targetID).load(FileToLoad, function(response, status, xhr) {
			if (status == 'error') {
				$.notify({
					text: 'Er is helaas iets mis gegaan:<br>' + xhr.status + ' ' + xhr.statusText, title:'Fout', icon:'images/dialog-error.png'
				});
			}
		}).fadeIn(300)
	});

}






$(document).bind("idle.idleTimer", function(){
 // function you want to fire when the user goes idle
 // Laat de server weten dat de gebruiker inactief is
 if (!IDLE_Active){
 IDLE_Active = true;
 $.getJSON("./src/login.json.php", { UserIsInActive: "true" }, function(j) {
     if(j[0].status == "succes"){	    			
     	showIDLE_Message('U was langer dan <?=$cfg['general']['idle']['min'];?> min inactief',j[0].UserName);
     	//$.idleTimer('destroy');
     }
  });
}
});
 
 
$(document).bind("active.idleTimer", function(){
 // function you want to fire when the user becomes active again
 //showIDLE_Message('U was langer dan 5 min inactief');
});
</script>

<div id="container">
	<div id="left-div">
		<div id="left-inside">
			<div style="clear: both;"></div>
			<div style="clear: both;"></div>								
				<div class="home-post-wrap2">
					<h2 class="titles">
						<?=$cfg['general']['welcome']['title'];?>
					</h2>
					<div style="clear: both;"></div>
					<?=$cfg['general']['welcome']['text'];?>
					<div style="clear: both;"></div>
				</div> <!-- end .home-post-wrap2 -->
		</div> <!-- end #left-inside -->
	</div> <!-- end #left-div -->
<div id="sidebar">
	    
    <div id="search-3" class="sidebar-box widget_search"><form method="POST" id="LoginForm" action="?login">
    <h2>Aanmelden</h2>
    <div>
    <? 
     	if (file_exists('./update.php')){
     		include('./update.php');
     		$dateDiff    = $update_time - time();
     		$fullDays    = floor($dateDiff/(60*60*24));
     		$fullHours   = floor(($dateDiff-($fullDays*60*60*24))/(60*60));
     		$fullMinutes = floor(($dateDiff-($fullDays*60*60*24)-($fullHours*60*60))/60);
     		$updateTextTime2 = "Differernce is $fullDays days, $fullHours hours and $fullMinutes minutes.";
     		if($fullDays <= -1){
     			$updateTextTime = "op dit moment wordt de site geupdate.";
     			$updateTextTimeDone= "1 uur";
     		}elseif($fullHours == '0'){
     			if($fullMinutes == '0'){
     				$updateTextTime = "op dit moment wordt de site geupdate.";
     				$updateTextTimeDone= "1 uur";
     			}else{
     				$updateTextTime = "over $fullMinutes minuten wordt de site geupdate.";
     				$updateTextTimeDone= "1 uur en $fullMinutes minuten";
     			}
     		}else{
     			$updateTextTime = "over $fullHours uur en $fullMinutes minuten wordt de site geupdate.";
     			$updateTextTimeDone = ($fullHours+1)." uur en $fullMinutes minuten";
     		}
     		
     		echo 'Aanmelden is op dit moment niet mogelijk:<br> '.$updateTextTime.'<br> Probeer het over '.$updateTextTimeDone.' nog eens...';
     	}else{
     ?>
    	<? if($cfg['general']['students_can_login']){echo "<select><option value='0'>ik ben een:</option><option value='1'>Docent</option><option value='2'>Leerling</option></select><br>";}?>
        <input type="text" value="Gebruikersnaam" name="gebruikersnaam" id="gebruikersnaam" tabindex="1" onkeypress="if (event.keyCode==13){if($('#wachtwoord').val() == '' || $('#wachtwoord').val() == 'Wachtwoord'){$('#wachtwoord_text').focus();}else{doJASON('aanmelden');}}" style="color:#CCC;" onfocus="this.style.color='#000';if (this.value =='Gebruikersnaam'){this.value ='';}" onblur="if(this.value == ''){this.style.color='#CCC';this.value ='Gebruikersnaam';}"/><br>
        <div class="but"><a href="javascript:void('0');" class="positive" name="inloggen" onclick="doJASON('aanmelden');"><img src="./images/icon-signin.png"/>Aanmelden</a></div>
        <input type="password" value="" name="wachtwoord" id="wachtwoord" tabindex="2" onkeypress="{if (event.keyCode==13)doJASON('aanmelden')}" onblur="if($('#wachtwoord').val() == ''){$('#wachtwoord_text').show();$('#wachtwoord').hide();}" style="display:none;" /><input type="text" value="Wachtwoord" name="wachtwoord" id="wachtwoord_text" onfocus="$('#wachtwoord_text').hide();$('#wachtwoord').show();$('#wachtwoord').focus();" style="color:#CCC;"/><br><a href="javascript:void('0');" onclick="showwwVergeten_Message();">Wachtwoord vergeten?</a>
        <? } ?>
    </div>
</form>
</div><div id="text-3" class="sidebar-box widget_text"><h2>Adres</h2>			<div class="textwidget"><p>CBS Groenhorst<br />
De Meent 3<br />
3833 EA Leusden<br />
Tel. 033 - 4943175</p>
</div>




			</div> <!-- end #sidebar -->
</div>
<div style="clear: both;"></div>
</div>


<div id="footer">&copy;CBS Groenhorst | 2012 <div style="float:right;padding-right: 20px;"> Ontwikkeld door <a href="http://laulaman.nl">Laurens Laman</a></div></div>
<!---PageLOADER-->
<div id="page-loader-background"></div>
<div id="page-loader"><a href="javascript:void('0');" id="page-loader-info" title="Laat zien wat er presies gebeurd"  onclick="$('#page-loader-detail').fadeToggle(300);"></a><h3 id="page-loader-title">Opslaan</h3><div id="page-loader-detail"><h1>Details</h1><p id="page-loader-detail-text"></p></p></div></div>
<!--END PageLOADER-->
<!---IDLE Message-->
<div id="idle-background"></div>
<div id="idle-display"><a href="javascript:void('0');" id="idle-icon"></a><h3 id="idle-title">U was langer dan <?=$cfg['general']['idle']['min'];?> min inactief.</h3><div id="idle-content">Als u langer dan <?=$cfg['general']['idle']['min'];?> min niets op het scherm doet moet u uit veiligheidsoverwegingen opnieuw uw wachtwoord invoeren om verder te kunnen werken.</div><div id="idle-username"></div><input type="password" name="p" value="" id="idle-password" style="display:none;" onblur="if($(this).val() == ''){$('#idle-password-info').show();$('#idle-password').hide();}" onkeypress="if (event.keyCode==13){IDLE_CheckPWD();}"  tabindex="4"/><input type="text" name="x"  tabindex="3" value="Wachtwoord" id="idle-password-info" onclick="$('#idle-password').show();$('#idle-password-info').hide();$('#idle-password').focus();"/><div class="but" id="idle-buttons"><a href="javascript:void('0');" class="positive" name="inloggen" onclick="IDLE_CheckPWD();"><img src="./images/icon-signin.png">Inloggen</a><a href="javascript:void('0');" onclick="hideIDLE_Message();doJASON('afmelden')" class="negative"><img src="./images/icon-signout.png">Afmelden</a></div></div>
<!--END IDLE Message-->
<!---UPDATE Message-->
<div id="UPDATE-background"></div>
<div id="UPDATE-display"><a href="javascript:void('0');" id="UPDATE-icon"></a><h3 id="UPDATE-title">Op dit moment wordt de site geüpdate</h3><div id="UPDATE-content">Tijdens het uitvoeren van de update is de site niet beschikbaar en kunt u geen wijzigingen uitvoeren..<br> dit venster verdwijnt zodra de update gereed is..<br><br><br><br><br><span style="color:#F00;">Let op: het kan zijn dat gegevens verloren gaan als deze nog niet opgeslagen waren.. houdt hier rekening mee</span></div></div>
<!--END UPDATE Message-->
<!---wwVergeten Message-->
<div id="wwVergeten-background"></div>
<div id="wwVergeten-display">
	<a href="javascript:void('0');" id="wwVergeten-icon"></a>
	<h3 id="wwVergeten-title">Nieuw wachtwoord aanvragen.</h3>
	<div id="wwVergeten-content">U bent uw wachtwoord vergeten. Om een nieuw wachtwoord aan te vragen dient u uw gebruikersnaam en email in te voeren. U krijgt dan per mail uw nieuwe wachtwoord toegestuurd.</div>
	<input type="text" name="ww_gebruikersnaam" value="Gebruikersnaam"  tabindex="5" id="wwVergeten-Gebruikersnaam" onblur="if (this.value =='' || this.value == 'Gebruikersnaam'){this.value ='Gebruikersnaam';this.style.color='#ccc';}" onfocus="this.style.color='#000';if (this.value =='Gebruikersnaam'){this.value ='';}" onkeypress="if (event.keyCode==13){if($('#wwVergeten-Email').val() != 'Email' && $('#wwVergeten-Gebruikersnaam').val() != 'Gebruikersnaam' && $('#wwVergeten-Email').val() != '' && $('#wwVergeten-Gebruikersnaam').val() != ''){wwVergete_Check();}else{$('#wwVergeten-Email').focus();}}"/>
	<input type="text" name="wwEmail" value="Email"  tabindex="6" id="wwVergeten-Email" onblur="if (this.value =='' || this.value == 'Email'){this.value ='Email';this.style.color='#ccc';}" onfocus="this.style.color='#000';if (this.value =='Email'){this.value ='';}" onkeypress="if (event.keyCode==13){if($('#wwVergeten-Email').val() != 'Email' && $('#wwVergeten-Gebruikersnaam').val() != 'Gebruikersnaam' && $('#wwVergeten-Email').val() != '' && $('#wwVergeten-Gebruikersnaam').val() != ''){wwVergete_Check();}else{$('#wwVergeten-Gebruikersnaam').focus();}}"/>
	<div class="but" id="wwVergeten-buttons">
		<a href="javascript:void('0');" onclick="hidewwVergeten_Message();" class="negative"><img src="./images/icon-cross.png" alt=""/>Annuleren</a>
		<a href="javascript:void('0');" onclick=" wwVergete_Check();"       class="positive"><img src="./images/icon-apply.png" alt=""/>Stuur</a>
	</div>
</div>
<!--END wwVergeten Message-->

<? 
if(isset($_GET['error'])){
	echo "<script>";
	echo "\$.notify({text: '".@$_GET['Text']."', title:'".@$_GET['Title']."', icon:'images/dialog-error.png'});";
	echo "</script>";
}
?>
	</body>
</html>
